Go To Script

I have a list of about 1000 object identifiers.  I want to run a script that searches for each one and returns how many were not found.

Module m = current
Object o
string attr = "ID"
int count = 0
int count2 = 0

for o in m do {

if o.attr = "<1000 objects here>" then {
count++
} else {
count2++}

print "Results Not Found:\t\t" count "\n"
print "Results Not Found:\t\t" count2 "\n"

 

I guess I need to figure out how to best do this.  I'd like to be able to take my list of numbers from Excel and just drop them into my code.  Should I just create an array like "Array numbers = create(int 1, int 2, int 3 . . . int 1000)"?


stevenson - Fri Jul 26 17:17:44 EDT 2013

Re: Go To Script
llandale - Sat Jul 27 16:23:20 EDT 2013

I think you have a list of ObjIDs perhaps in Excel, and you want a DXL that reads the list and tells you which ones actually exist in a particular module and which do not.

  • If you are looking for "Object Identifier" then know that is not actually an attribute ..
    • get it's value with "identifier(o)"
  • Unless you are assigning an actual attribute value to a variable, you must convert the attr into a string:
    • o.att ""

Let me scribble an outline:

  • Skip skpIDs = createString   // KEY and DATA both 'string' "ID" read from the file
  • Stream inFile = read("c:/MyFolder/MyListOfIDs.txt")
  • for each line in the inFile
  • {  put(skpIDs, ID, ID)
  • }
  • Skip skpObjs = create()   // KEY 'string' ObjID; DATA: 'Object' handle
  • for o in entire mod do
  • {  if (!isDeleted(o)) put(skpObjs, identifier(o), o)
  • }
  • for ID in skpIDs do
  • {  if (find(skpObjs, ID, o)) //
  •    then found it in Object o
  •    else not found it
  • }

-Louie

Re: Go To Script
stevenson - Mon Jul 29 11:26:00 EDT 2013

llandale - Sat Jul 27 16:23:20 EDT 2013

I think you have a list of ObjIDs perhaps in Excel, and you want a DXL that reads the list and tells you which ones actually exist in a particular module and which do not.

  • If you are looking for "Object Identifier" then know that is not actually an attribute ..
    • get it's value with "identifier(o)"
  • Unless you are assigning an actual attribute value to a variable, you must convert the attr into a string:
    • o.att ""

Let me scribble an outline:

  • Skip skpIDs = createString   // KEY and DATA both 'string' "ID" read from the file
  • Stream inFile = read("c:/MyFolder/MyListOfIDs.txt")
  • for each line in the inFile
  • {  put(skpIDs, ID, ID)
  • }
  • Skip skpObjs = create()   // KEY 'string' ObjID; DATA: 'Object' handle
  • for o in entire mod do
  • {  if (!isDeleted(o)) put(skpObjs, identifier(o), o)
  • }
  • for ID in skpIDs do
  • {  if (find(skpObjs, ID, o)) //
  •    then found it in Object o
  •    else not found it
  • }

-Louie

You'll have to excuse my novice-level experience, but I've yet to use Skip or Stream commands.  They seem incredibly powerful and useful from what I've read and very much applicable to what I'm trying to accomplish.  Anyway, I've been trying to just use the Stream command, but I keep receiving " badly formed token ("C:\Users\tesla\Desktop\list.txt"))".  The file is just a text file with numbers listed in a vertical column.  Do I need to save it in another format?
 

I can concatenate my array in excel and use the following simplified script:

Module m = current
Object o
string ID
int count
int count2
Array checkIDs = create(2,1)
put(checkIDs, ID, 2, 23)

for ID in checkIDs do {  
if find(ID)
then count++
else count2++
}
 

Unfortunately I keep getting incorrect arguments for 'do' and syntax error at 'then count++'.  Any ideas?

Re: Go To Script
llandale - Mon Jul 29 16:21:44 EDT 2013

stevenson - Mon Jul 29 11:26:00 EDT 2013

You'll have to excuse my novice-level experience, but I've yet to use Skip or Stream commands.  They seem incredibly powerful and useful from what I've read and very much applicable to what I'm trying to accomplish.  Anyway, I've been trying to just use the Stream command, but I keep receiving " badly formed token ("C:\Users\tesla\Desktop\list.txt"))".  The file is just a text file with numbers listed in a vertical column.  Do I need to save it in another format?
 

I can concatenate my array in excel and use the following simplified script:

Module m = current
Object o
string ID
int count
int count2
Array checkIDs = create(2,1)
put(checkIDs, ID, 2, 23)

for ID in checkIDs do {  
if find(ID)
then count++
else count2++
}
 

Unfortunately I keep getting incorrect arguments for 'do' and syntax error at 'then count++'.  Any ideas?

C:\Users\tesla\Desktop\list.txt

Its the back-slashes; a very common mistake.  A backslash is the "escape" character and since there is no escape for "U" you get the error.  Either convert them all to double slashes or better yet get in the habit of using frontslashes:

  • "C:\\Users\\tesla\\Desktop\\list.txt"
  • "C:/Users/tesla/Desktop/list.txt"

-Louie

My notes say these are the ONLY valid escaped characters; the manual is wrong:    \b  t  \n  \v  \f  \r  \\

Re: Go To Script
stevenson - Mon Jul 29 18:32:59 EDT 2013

llandale - Mon Jul 29 16:21:44 EDT 2013

C:\Users\tesla\Desktop\list.txt

Its the back-slashes; a very common mistake.  A backslash is the "escape" character and since there is no escape for "U" you get the error.  Either convert them all to double slashes or better yet get in the habit of using frontslashes:

  • "C:\\Users\\tesla\\Desktop\\list.txt"
  • "C:/Users/tesla/Desktop/list.txt"

-Louie

My notes say these are the ONLY valid escaped characters; the manual is wrong:    \b  t  \n  \v  \f  \r  \\

I've tried to modify the script to the following:

 

Module m = current
Object o
string ID
int count
int count2
Skip skpIDs = createString   // KEY and DATA both 'string' "ID" read from the file
Stream inFile = read("C:/Users/e814484/Desktop/list.txt")

while (true)
{ inFile << "C:/Users/e814484/Desktop/list.txt"
// read a line at a time

if (end inFile)
break
else put(skpIDs, ID, ID)
continue 
//skip to next line to read in

Skip skpObjs = create()   // KEY 'string' ObjID; DATA: 'Object' handle
for o in m do
{  if (!isDeleted(o)) put(skpObjs, identifier(o), o)
}
for ID in skpIDs do
{  if (find(skpObjs, ID, o)) 
   then count++
  else count2++
}

print "Results Found:\t\t" count "\n"
print "Results Not Found:\t\t" count2 "\n"

 

I'm not sure I'm accessing the Stream the correct way to read line by line, but the only errors that appear when I try to run the script are at 'then count++' (line 25), which is a syntax error and line 32, which is not even a line in the code (only 30 lines) but also appears as a syntax error.

Re: Go To Script
Tony_Goodman - Tue Jul 30 03:44:25 EDT 2013

stevenson - Mon Jul 29 18:32:59 EDT 2013

I've tried to modify the script to the following:

 

Module m = current
Object o
string ID
int count
int count2
Skip skpIDs = createString   // KEY and DATA both 'string' "ID" read from the file
Stream inFile = read("C:/Users/e814484/Desktop/list.txt")

while (true)
{ inFile << "C:/Users/e814484/Desktop/list.txt"
// read a line at a time

if (end inFile)
break
else put(skpIDs, ID, ID)
continue 
//skip to next line to read in

Skip skpObjs = create()   // KEY 'string' ObjID; DATA: 'Object' handle
for o in m do
{  if (!isDeleted(o)) put(skpObjs, identifier(o), o)
}
for ID in skpIDs do
{  if (find(skpObjs, ID, o)) 
   then count++
  else count2++
}

print "Results Found:\t\t" count "\n"
print "Results Not Found:\t\t" count2 "\n"

 

I'm not sure I'm accessing the Stream the correct way to read line by line, but the only errors that appear when I try to run the script are at 'then count++' (line 25), which is a syntax error and line 32, which is not even a line in the code (only 30 lines) but also appears as a syntax error.

Here you go...

 

Module m = current
Object o = null
string ID = ""
int count = 0
int count2 = 0
 
Skip skpObjs = createString   // KEY 'string' ObjID; DATA: 'Object' handle
Skip skpIDs = createString   // KEY and DATA both 'string' "ID" read from the file
 
Stream inFile = read("U:/list.txt")
 
// read identifiers from text file into a skip list
while (!end inFile)
{
inFile >> ID
 
put(skpIDs, ID, ID)
}
 
close(inFile)
 
// read object identifiers into a skip list
for o in m do
{  
put(skpObjs, identifier(o), identifier(o))
}
 
// for each identifier in the first skip list, see if it exists in the second
for ID in skpIDs do
{  
if (find(skpObjs, ID, o))
{
// identifier  exists in doors
  count++
}
else
{
// identifier does not exist in doors
count2++
}
}
 
print "Results Found:\t\t" count "\n"
print "Results Not Found:\t\t" count2 "\n"

 

Re: Go To Script
stevenson - Tue Jul 30 12:32:28 EDT 2013

Tony_Goodman - Tue Jul 30 03:44:25 EDT 2013

Here you go...

 

Module m = current
Object o = null
string ID = ""
int count = 0
int count2 = 0
 
Skip skpObjs = createString   // KEY 'string' ObjID; DATA: 'Object' handle
Skip skpIDs = createString   // KEY and DATA both 'string' "ID" read from the file
 
Stream inFile = read("U:/list.txt")
 
// read identifiers from text file into a skip list
while (!end inFile)
{
inFile >> ID
 
put(skpIDs, ID, ID)
}
 
close(inFile)
 
// read object identifiers into a skip list
for o in m do
{  
put(skpObjs, identifier(o), identifier(o))
}
 
// for each identifier in the first skip list, see if it exists in the second
for ID in skpIDs do
{  
if (find(skpObjs, ID, o))
{
// identifier  exists in doors
  count++
}
else
{
// identifier does not exist in doors
count2++
}
}
 
print "Results Found:\t\t" count "\n"
print "Results Not Found:\t\t" count2 "\n"

 

Thank you both very much!